/**
 * @author Juko
 */
package ganga.custodian.ui;

import ganga.custodian.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Преобразует список {@link} ListViewItem для представления в {@link} ListView
 * 
 * @author Apocrypha
 */
public class ListViewAdapter extends BaseAdapter  {
    public ListViewAdapter(Context context, List<ListViewItem> listView) {
        this.context = context;
        this.list = listView;
    }
	public int getCount() {
		return list.size();
	}
    public Object getItem(int position) {
        return list.get(position);
    }
    public long getItemId(int position) {
        return position;
    }
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ListViewItem entry = list.get(position);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.listviewitem, null);
        }
        TextView tvContact = (TextView) convertView.findViewById(R.id.tvAdapter);
        tvContact.setText(entry.getName());

        TextView tvPhone = (TextView) convertView.findViewById(R.id.tvManual);
        tvPhone.setText(entry.getDescription());
        
        ImageView iconView = (ImageView) convertView.findViewById(R.id.imageView1);
        iconView.setImageResource(entry.getIconId());

        return convertView;
    }

    private Context context;
	private List<ListViewItem> list;
}